<?php
namespace app\channel\controller;

use app\common\controller\ChannelBase;

use app\common\model\Order   as GamePayLogModel;
use app\common\model\Gamelist   as GameListModel;
use app\common\model\Gameagent  as GameAgentModel;
use app\common\model\Player as PlayerModel;
use think\Config;
use think\Db;
use think\facade\Session;

/**
 * 玩家管理
 * Class AdminUser
 * @package app\admin\controller
 */
class Order extends ChannelBase
{
    
    protected function _initialize()
    {
        parent::_initialize();
    }
    

    /**
     * 充值记录
     * @param string $keyword
     * @param int    $page
     * @return mixed
     */
    public function index($page = 1)
    {
		/* 查询条件初始化 */
    	$data = input();
        $map[]  = ['cid' ,'=',Session::get('channel_id')];
        if(!empty($data['keyword'])){
		$map[]  = ['a.uid|a.order_no','like', '%'.$data['keyword'].'%'];
        }
        if(!empty($data['game'])){
            $map[]   = ['a.gid','=' ,$data['game']];
        }else{
		    $data['game']   = null;
		}
        if(!empty($data['area'])){
            $map[]  = ['a.sid','=',$data['area']];
        }

        $map[]  = ['a.order_status','gt',0];
        $page = input('page') ? input('page') : 1;

        if (!empty($data['starttime']) && !empty($data['endtime'])) {
            $map[]= ['a.pay_time','between time',[$data['starttime'],$data['endtime']]];
        }elseif (!empty($data['starttime'])) {
            $map[] = ['a.pay_time','>=',$data['starttime']];
        }elseif (!empty($data['endtime'])) {
            $map[] = ['a.pay_time','<=',$data['endtime']];
        }
		$field = 'a.*,b.name,c.sname,d.username as aname,d.nickname';
		//$pay_list = GamePModel::alias('a')->join('Gamelist b','b.id = a.gid','left')->join('Gamearea c','c.id = a.sid','left')->where($map)->field($field)->order('a.id DESC')->paginate(15, false, ['page' => $page,'query' =>request()->param()]);
		$pay_list = GamePayLogModel::alias('a')
            ->join('Gamelist b','b.id = a.gid','left')
            ->join('Gamearea c','c.sid = a.sid','left')
            ->join('Channel d','d.id = a.cid','left')
            ->where($map)->field($field)
            ->order('a.id DESC')
            ->paginate(100, false, ['page' => $page,'query' =>request()->param()]);
		$game_list = GameListModel::order('id DESC')->select();
        $this->assign('game_list',$game_list);
        $this->assign('pay_list',$pay_list);
        $this->assign('data',$data);
        return $this->fetch();
    }

}